#analysis for NETFLIX company stock datasets
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
df_close=pd.DataFrame()
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/nflx/chart/2y")
df_item.head(5)
#df_item.set_index('date',inplace=True)
#Took only 5 fetures out of api
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("mynetflixdata.csv", encoding='utf-8', index=True)
df = pd.read_csv('mynetflixdata.csv', index_col=0)
#for getting data only of 1 year that is 01-01-2017 to 31-12-2017
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("mynetflixdata.csv", encoding='utf-8', index=True)
dat=pd.read_csv('mynetflixdata.csv', index_col=0)
from datetime import datetime
sns.set_style('darkgrid')
dat['date'] = pd.to_datetime(dat['date'])
#set date as ndex
dat = dat.set_index('date')
#ploat graph of closing of stocks of netflix
dat['close'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#ax = dat.plot()
#ploat of the graph of opening rate of stocks of netflix
dat['open'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#graph of lowest rate of stock of netflix
plt.ylabel('$(USD)', fontsize=18)
dat['low'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#graph of volumes of stocks of netflix company
dat['volume'].plot(legend=True, figsize=(10,4))
plt.ylabel('Volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#graph of high value of stocks of netflix dataset
dat['high'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#graph of netflix stock's data for high,low,open,close,volume
dat1=dat[['high','low','open','close']]
ax = dat1.plot()
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#mean calculation of data of netflix'stocks
#here only closing rate of netflix with various time span
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['close'],i)
dat[['close','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['open'],i)
dat[['open','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#mean of netflix data of volume for various days
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['volume'],i)
dat[['volume','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#mean of netflix data of low rate of stocks for various days span
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['low'],i)
dat[['low','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#mean of high values for various days of netflix'stocks
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['high'],i)
dat[['high','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Netflix', fontsize=20)
#daily return of netflix stoks
# We'll use pct_change to find the percent change for each day
dat['Daily Return'] = dat['close'].pct_change()
# Lets plot the daily return percentage
dat['Daily Return'].plot(figsize=(12,4), legend=True, linestyle='--', marker='d')
plt.suptitle('Netflix', fontsize=20)
plt.xlabel('Months', fontsize=18)
dat['Daily Return'].hist(bins=100)
plt.suptitle('Netflix', fontsize=20)
dat
#for google dataset
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
df_close=pd.DataFrame()
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/googl/chart/2y")
df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("mygoogledata.csv", encoding='utf-8', index=True)
df = pd.read_csv('mygoogledata.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("mygoogledata.csv", encoding='utf-8', index=True)
dat=pd.read_csv('mygoogledata.csv', index_col=0)
from datetime import datetime
sns.set_style('darkgrid')
dat['date'] = pd.to_datetime(dat['date'])
dat = dat.set_index('date')
dat['close'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
#ax = dat.plot()
dat['open'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
dat['low'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
dat['high'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
dat['volume'].plot(legend=True, figsize=(10,4))
plt.ylabel('Volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
dat1=dat[['high','low','open','close']]
ax = dat1.plot()
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['open'],i)
dat[['open','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['close'],i)
dat[['close','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['low'],i)
dat[['low','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['volume'],i)
dat[['volume','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('Volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['high'],i)
dat[['high','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
#daily return of google's stoks
# We'll use pct_change to find the percent change for each day
dat['Daily Return'] = dat['close'].pct_change()
# Lets plot the daily return percentage
dat['Daily Return'].plot(figsize=(12,4), legend=True, linestyle='--', marker='d')
plt.xlabel('Months', fontsize=18)
plt.suptitle('Google', fontsize=20)
dat['Daily Return'].hist(bins=100)
plt.suptitle('Google', fontsize=20)
#for FACEBOOK
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
df_close=pd.DataFrame()
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/fb/chart/2y")
df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("myfacebookdata.csv", encoding='utf-8', index=True)
df = pd.read_csv('myfacebookdata.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("myfacebookdata.csv", encoding='utf-8', index=True)
dat=pd.read_csv('myfacebookdata.csv', index_col=0)
from datetime import datetime
sns.set_style('darkgrid')
dat['date'] = pd.to_datetime(dat['date'])
dat = dat.set_index('date')
dat['close'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
#ax = dat.plot()
dat['open'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
dat['low'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
dat['high'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
dat['volume'].plot(legend=True, figsize=(10,4))
plt.ylabel('volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
dat1=dat[['high','low','open','close']]
ax = dat1.plot()
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['volume'],i)
dat[['volume','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['open'],i)
dat[['open','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['close'],i)
dat[['close','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['low'],i)
dat[['low','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['high'],i)
dat[['high','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
#daily return of Facebook stoks
# We'll use pct_change to find the percent change for each day
dat['Daily Return'] = dat['close'].pct_change()
# Lets plot the daily return percentage
dat['Daily Return'].plot(figsize=(12,4), legend=True, linestyle='--', marker='d')
plt.xlabel('Months', fontsize=18)
plt.suptitle('Facebook', fontsize=20)
dat['Daily Return'].hist(bins=100)
plt.suptitle('Facebook', fontsize=20)
# FOR AMAZON
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
df_close=pd.DataFrame()
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/amzn/chart/2y")
df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("myamazondata.csv", encoding='utf-8', index=True)
df = pd.read_csv('myamazondata.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("myamazondata.csv", encoding='utf-8', index=True)
dat=pd.read_csv('myamazondata.csv', index_col=0)
from datetime import datetime
sns.set_style('darkgrid')
dat['date'] = pd.to_datetime(dat['date'])
dat = dat.set_index('date')
dat['close'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
#ax = dat.plot()
dat['open'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
dat['low'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
dat['high'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
dat['volume'].plot(legend=True, figsize=(10,4))
plt.ylabel('volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
dat1=dat[['high','low','open','close']]
ax = dat1.plot()
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
#daily return of Amazon's stoks
# We'll use pct_change to find the percent change for each day
dat['Daily Return'] = dat['close'].pct_change()
# Lets plot the daily return percentage
dat['Daily Return'].plot(figsize=(12,4), legend=True, linestyle='--', marker='d')
plt.ylabel('precent', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
dat['Daily Return'].hist(bins=100)
plt.suptitle('Amazon', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['close'],i)
dat[['close','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['open'],i)
dat[['open','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['low'],i)
dat[['low','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['high'],i)
dat[['high','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['volume'],i)
dat[['volume','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Amazon', fontsize=20)
#FOR APPLE
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
df_close=pd.DataFrame()
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/aapl/chart/2y")
df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("myappledata.csv", encoding='utf-8', index=True)
df = pd.read_csv('myappledata.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("myappledata.csv", encoding='utf-8', index=True)
dat=pd.read_csv('myappledata.csv', index_col=0)
from datetime import datetime
sns.set_style('darkgrid')
dat['date'] = pd.to_datetime(dat['date'])
dat = dat.set_index('date')
dat['close'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
#ax = dat.plot()
dat['open'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
dat['low'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
dat['high'].plot(legend=True, figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
dat['volume'].plot(legend=True, figsize=(10,4))
plt.ylabel('volumes', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
#daily return of Apple's stoks
# We'll use pct_change to find the percent change for each day
dat['Daily Return'] = dat['close'].pct_change()
# Lets plot the daily return percentage
dat['Daily Return'].plot(figsize=(12,4), legend=True, linestyle='--', marker='d')
plt.ylabel('percent', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
dat['Daily Return'].hist(bins=100)
plt.suptitle('Apple', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['open'],i)
dat[['open','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['close'],i)
dat[['close','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['low'],i)
dat[['low','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['high'],i)
dat[['high','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('$(USD)', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
Span_day = [30,60,90,120,150,180,210,240,270,300,330,350]
for i in Span_day:
column_name = 'mean for %s days' %(str(i))
dat[column_name] = pd.rolling_mean(dat['volume'],i)
dat[['volume','mean for 30 days','mean for 60 days','mean for 90 days','mean for 120 days','mean for 150 days','mean for 180 days','mean for 210 days','mean for 240 days','mean for 270 days','mean for 300 days','mean for 330 days','mean for 350 days']].plot(subplots=False,figsize=(10,4))
plt.ylabel('volume', fontsize=18)
plt.xlabel('Months', fontsize=18)
plt.suptitle('Apple', fontsize=20)
#here i take datas's of all company and merge them in a single datafrmae i took close price of all company for one year
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
df_close=pd.DataFrame()
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/nflx/chart/2y")
#df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("mynetflixdata1.csv", encoding='utf-8', index=True)
df = pd.read_csv('mynetflixdata1.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("mynetflixdata1.csv", encoding='utf-8', index=True)
dat1=pd.read_csv('mynetflixdata1.csv', index_col=0)
####
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/googl/chart/2y")
#df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("mygoogledata1.csv", encoding='utf-8', index=True)
df = pd.read_csv('mygoogledata1.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("mygoogledata1.csv", encoding='utf-8', index=True)
dat2=pd.read_csv('mygoogledata1.csv', index_col=0)
######
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/fb/chart/2y")
#df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("myfacebookdata1.csv", encoding='utf-8', index=True)
df = pd.read_csv('myfacebookdata1.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("myfacebookdata1.csv", encoding='utf-8', index=True)
dat3=pd.read_csv('myfacebookdata1.csv', index_col=0)
#####
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/amzn/chart/2y")
#df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("myamazondata1.csv", encoding='utf-8', index=True)
df = pd.read_csv('myamazondata1.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("myamazondata1.csv", encoding='utf-8', index=True)
dat4=pd.read_csv('myamazondata1.csv', index_col=0)
#######
df_item=pd.read_json("https://api.iextrading.com/1.0/stock/aapl/chart/2y")
#df_item.head(5)
#df_item.set_index('date',inplace=True)
df_close=df_item[['date','high','low','open','close','volume']]
df_close.to_csv("myappledata1.csv", encoding='utf-8', index=True)
df = pd.read_csv('myappledata1.csv', index_col=0)
val=df.tail(1).index.item()
df['date'] = pd.to_datetime(df['date'])
df['date'] = pd.date_range('2017-01-01', periods=val+1, freq='D')
mask = (df['date'] > '2017-01-01') & (df['date'] <= '2017-12-31')
df.loc[mask].to_csv("myappledata1.csv", encoding='utf-8', index=True)
dat5=pd.read_csv('myappledata1.csv', index_col=0)
df_close=pd.DataFrame()
#make a list
df_close=[dat1['close'],dat2['close'],dat3['close'],dat4['close'],dat5['close']]
#convert o the dataframe
f = pd.DataFrame(df_close)
#transpose it
f1=f.transpose()
#change the header's name
f1.columns = ['Netflix', 'Google','Facebook','Amazon','Apple']
f1
f1.plot()
plt.rc('figure', figsize=(20, 10))
#graph of closing prize of stocks of all comapies with pairplot
sns.pairplot(f1.dropna(),size=3)
#compairing closing price of the comapny with joinplot
sns.jointplot(f1['Google'],f1['Amazon'],dat,kind='scatter',color='orange')
sns.jointplot(f1['Facebook'],f1['Apple'],dat, kind='reg', size=8, color='skyblue')
# Set up the figure by naming it returns_fig, call PairGrid on the DataFrame
returns_fig = sns.PairGrid(f1.dropna())
# Using map_upper we can specify what the upper triangle will look like.
returns_fig.map_upper(plt.scatter,color='purple')
# We can also define the lower triangle in the figure, including the plot type (kde) & the color map (BluePurple)
returns_fig.map_lower(sns.kdeplot,cmap='cool_d')
# Finally we'll define the diagonal as a series of histogram plots of the daily return
returns_fig.map_diag(plt.hist,bins=30)
#ploating of closing price of all 5 comapny with heatmap
sns.heatmap(f1.corr(),annot=True,fmt=".3g",cmap='YlGnBu')
#calculate standard deviation in closing price of all companies
f2=f1.std()
f2.plot.bar()
plt.suptitle('standard deviation', fontsize=20)
plt.rc('figure', figsize=(10, 10))